﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace _2_Services
{
    public static class CjwDbContext
    {
        /// <summary>
        /// 创建SqlSugarClient
        /// </summary>
        /// <returns></returns>
        public static SqlSugarClient GetInstance()
        {
            //创建数据库对象
            SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
            {
                //数据库连接符字串
                ConnectionString = "server=118.31.170.229;userid=cjw;pwd=Cjw123456.;database=cjw_db;sslmode=none;",
                DbType = DbType.MySql,
                IsAutoCloseConnection = true
            });

            //输出sql,查看执行sql
            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql);
            };
            return Db;
        }
    }
}
